<?php
class keu_closing_model extends MY_Model {
	var $model = 'keu_closing';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT KEU_CLOSING.KD_KANTOR, 
							TO_CHAR(KEU_CLOSING.MONTH_YEAR,'YYYY-MM-DD') MONTH_YEAR, 
							KEU_CLOSING.STATUS_CLOSED,
							SW_KANTOR.NAMA_KANTOR  NAMA_KANTOR
					FROM 
					KEU_CLOSING, SW_KANTOR
					WHERE KEU_CLOSING.KD_KANTOR = SW_KANTOR.KD_KANTOR AND
						MONTH_YEAR = TO_DATE('".post('month_year')."-01"."','YYYY-MM-DD')
					ORDER BY ".(post('sort')=='' ? 'SW_KANTOR.NAMA_KANTOR' : post('sort'))." ".(post('order')=='' ? 'ASC' : post('order'));
		
		return json_encode( $this->paging($ls_sql) );
	}
	
	function Update($arr_data, $arr_closing){
		$this->db->update('KEU_CLOSING', $arr_data, $arr_closing);
	}
	
	function Gen($month_year){
		$ls_sql = "INSERT INTO KEU_CLOSING (KD_KANTOR, MONTH_YEAR, STATUS_CLOSED, CREATE_USER, CREATE_DATE)
					SELECT KD_KANTOR, TO_DATE('".$month_year."','YYYY-MM-DD'), 'N', '".USERID."', SYSDATE FROM SW_KANTOR ";
					
					echo $ls_sql;
		$this->db->query($ls_sql);
	}
	
	function Closing($month_year){
		$ls_sql = "UPDATE KEU_CLOSING SET STATUS_CLOSED = 'Y' WHERE MONTH_YEAR = TO_DATE('".$month_year."', 'YYYY-MM-DD')";
		$this->db->query($ls_sql);
	}
}
?>